package mfuny.ggongal.admin.faq;

import java.util.HashMap;
import java.util.List;

import mfuny.ggongal.admin.Server;
import mfuny.ggongal.admin.games.GameDao;
import mfuny.ggongal.admin.json.JsonCreater;

import org.json.simple.JSONObject;
import org.junit.internal.matchers.Each;
import org.springframework.web.servlet.ModelAndView;

import com.ibatis.sqlmap.client.SqlMapClient;

public class FaqService {
    SqlMapClient sqlMapper;
    ModelAndView mav;
    
    public FaqService() throws Exception {
        sqlMapper = Server.getSqlMapper();
        mav = new ModelAndView();
    }

    @SuppressWarnings("unchecked")
    public ModelAndView regFaqForm(){
        mav.clear();
        mav.setViewName("/faq/regFaqForm.ga");
        List<HashMap<String,Object>> list = null;
        try{
            list=sqlMapper.queryForList("faq_select_for_web_list", null);
        }catch(Exception e){
            e.printStackTrace();
        }
        mav.addObject("list",list);
        return mav;
    }
    
    @SuppressWarnings("unchecked")
    public ModelAndView regFaq(FaqDao faqDao){
        mav.clear();
        mav.setViewName("/faq/regFaqForm.ga");
        List<HashMap<String,Object>> list = null;
        try{
            sqlMapper.update("faq_insert", faqDao);
        }catch(Exception e){
            e.printStackTrace();
        }
        try{
            list=sqlMapper.queryForList("faq_select_for_web_list", null);
        }catch(Exception e){
            e.printStackTrace();
        }
        mav.addObject("list",list);
        return mav;
    }
    @SuppressWarnings("unchecked")
    public ModelAndView readFaqForApp(int num){
        mav.clear();
        mav.setViewName("/faq/readFaqForApp");
        
        HashMap<String,Object> hm=null;
        try{
            hm=(HashMap<String, Object>) sqlMapper.queryForObject("faq_select", num);
        }catch(Exception e){
            e.printStackTrace();
        }
        mav.addObject("record",hm);
        return mav;
    }
    
}
